const path = require('path');
const webpack = require('webpack');
const pkg = require('../package.json');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const vConsolePlugin = require('vconsole-webpack-plugin'); 

const banner = `name: ${pkg.name} \n version: v${pkg.version} \n`;

// 接收运行参数
const argv = require('yargs')
    .describe('debug', 'debug 环境') // use 'webpack --debug'
    .argv;

console.log(`vconsole: ${argv.debug}`);

module.exports = {
    mode: 'development',
    entry: './src/index.js',
    output: {
        filename: `canvasTable.v${pkg.version}.js`,
        path: path.resolve(__dirname, '../dist')
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: "babel-loader"
                // use: [
                //     "babel-loader",
                //     "eslint-loader",
                // ]
            },
            {
                enforce: "pre",
                test: /\.js$/,
                exclude: /node_modules/,
                loader: "eslint-loader",
                options: {
                    emitError: true,
                    formatter: require("eslint-friendly-formatter")
                }
            }
        ]
    },
    // externals: {
    //     'Hammer': 'window.Hammer'
    // },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.BannerPlugin(banner),
        // new CopyWebpackPlugin([
        //     { from: 'src/libs', to: 'libs' }
        // ]),
        new vConsolePlugin({
            filter: [],  // 需要过滤的入口文件
            enable: !!argv.debug // 发布代码前记得改回 false
        })
    ]
};